package top.humbleyuan.java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author HumbleYuan
 * @Date 2020/1/3 14:01
 * @Des stream流计算
 */
public class StreamDemo {
    public static void main(String[] args) {
        List<User> userList = new ArrayList<>();
        User u1 = new User("1", "男",20);
        User u2 = new User("2", "男",25);
        User u3 = new User("3", "男",26);
        User u4 = new User("4", "女",27);
        User u5 = new User("5", "男",28);
        User u6 = new User("6", "女",29);
        User u7 = new User("7", "男",25);
        User u8 = new User("8", "女",29);
        User u9 = new User("9", "男",18);
        User u10 = new User("10", "女",40);

        userList = Arrays.asList(u1,u2,u3,u4,u5,u6,u7,u8,u9,u10);
        userList.stream().filter(user -> {
            return "男".equals(user.getSex());
        }).map(user -> {
            user.setSex("女");
            return user;
        }).sorted((o1, o2) -> {
            return o2.getUsername().compareTo(o1.getUsername());
        }).limit(2).forEach(System.out::println);


        // .stream是list转stream,.collect是stream转list
        userList.stream().collect(Collectors.toList());

    }
}
